package lsf.itcast.dao;

import lsf.itcast.domain.Member;
import lsf.itcast.domain.Orders;
import lsf.itcast.domain.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrdersDao {
    //查询所有订单
    @Select("select * from orders ")
    @Results({@Result(id = true,property = "id", column = "id"),
            @Result(property = "orderNum", column = "orderNum"),
            @Result(property = "orderTime", column = "orderTime"),
            @Result(property = "orderStatus", column = "orderStatus"),
            @Result(property = "payType", column = "payType"),
            @Result(property = "orderDesc", column = "orderDesc"),
            @Result(property = "peopleCount", column = "peopleCount"),
            @Result(property = "product", column = "productId",javaType =Product.class,
            one = @One(select = "lsf.itcast.dao.ProductDao.findById"))
       })
    public List<Orders> findAllOrder();



    //查询订单详情，包含了产品信息
    @Select("select * from orders where id=#{id} ")
    @Results({@Result(id = true,property = "id", column = "id"),
            @Result(property = "orderNum", column = "orderNum"),
            @Result(property = "orderTime", column = "orderTime"),
            @Result(property = "orderStatus", column = "orderStatus"),
            @Result(property = "payType", column = "payType"),
            @Result(property = "orderDesc", column = "orderDesc"),
            @Result(property = "peopleCount", column = "peopleCount"),
            @Result(property = "product", column = "productId",javaType =Product.class,
                    one = @One(select = "lsf.itcast.dao.ProductDao.findById")),
            @Result(property = "travellers",column = "id" ,javaType =java.util.List.class,
               many = @Many(select = "lsf.itcast.dao.TravellerDao.findById")),
            @Result(property = "member", column = "MemberId",javaType =Member.class,
                    one = @One(select = "lsf.itcast.dao.MemberDao.findById"))

    })
    Orders findById(String id);
}
